package cn.gson.crmdemo.controller.privilege;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;

import cn.gson.crmdemo.model.pojo.Dept;
import cn.gson.crmdemo.model.service.PrivilegeService;
import cn.gson.crmdemo.model.vo.DeptVo;

@Controller
public class DeptController {
	@Autowired
	PrivilegeService ps;
	/**
	 * 查询所有部门
	 * @return
	 */
	@RequestMapping("dept-All")
	@ResponseBody
	public  JSONArray  selectEmpAll() {
		JSONArray list = ps.selectDeptAll();
		return list;
	}
	
	@RequestMapping("dept-Alls")
	@ResponseBody
	public  List<Dept> selectDeptAll() {
		return ps.selectAllDept();
	}
	
	/**
	 * 查询部门详情
	 */
	/*@RequestMapping("dept-xq")
	@ResponseBody
	public Map<String, Object> selectDeptXq(Integer deptId){
		return ps.selectDeptXq(deptId);
	}*/
	/**
	 * 新增部门
	 */
	@RequestMapping("add-dept")
	public String addDept(DeptVo dept) {
		boolean b = ps.addDept(dept);
		if(b) { 
			return "redirect:dept-Alls";
		}
		return "sdfg";
	}
	/**
	 * 查询部门经理和助手编号
	 */
	/*@RequestMapping("dept-jlzs")
	@ResponseBody
	public JSONArray selectDeptSjZs(Integer deptId) {
		return ps.selectDeptSjZs(deptId);
	}*/
	/**
	 * 设置部门经理
	 */
	@RequestMapping("dept-jl")
	public String deptJl(Integer deptId,Integer empId) {
		ps.deptJl(deptId, empId);
		return "redirect:dept-Alls";
	}
	/**
	 * 设置部门助手
	 */
	@RequestMapping("dept-zs")
	public String deptZs(Integer deptId,Integer empId) {
		ps.deptZs(deptId, empId);
		return "redirect:dept-Alls";
	}
	/**
	 * 删除部门
	 * @return
	 */
	@RequestMapping("delete-dept")
	public String deleteDept(Integer deptId) {
		boolean b = ps.deleteDept(deptId);
		if(b) {
			return "redirect:dept-Alls";
		}
		return "asdfg";
	}
}
